package com.xqls.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xqls.bean.AdministrationBean;
import com.xqls.dal.dao.AdministrationDao;
import com.xqls.dal.model.Administration;
import com.xqls.service.AdministrationService;
import com.xqls.util.ObjectUtil;
@Service
public class AdministrationServiceImpl implements AdministrationService{
	
	
	@Autowired private AdministrationDao administrationDao;
	
	public List<Map<String, Object>> selectByMap(Map<String, Object> map){
		List<Map<String, Object>> dataList = administrationDao.selectByMap(map);
		for (Map<String,Object> data : dataList) {//displayfield,hiddenfield
			String displayfieldString = "";
			String disArrary[] = data.get("displayfield").toString().split(",");
			for (int i=0;i<disArrary.length;i++){
				String context = StringUtils.substringBeforeLast(disArrary[i], ":");
				displayfieldString += context+",";
			}
			displayfieldString = displayfieldString.substring(0,displayfieldString.length()-1);
			data.put("displayfieldString",displayfieldString);
			String hiddenfieldString = "";
			String hiddnArrary[] = data.get("hiddenfield").toString().split(",");
			for (int i=0;i<hiddnArrary.length;i++){
				String context = StringUtils.substringBeforeLast(hiddnArrary[i], ":");
				hiddenfieldString += context+",";
			}
			hiddenfieldString = hiddenfieldString.substring(0,hiddenfieldString.length()-1);
			data.put("hiddenfieldString",hiddenfieldString);
		}
		return dataList;
	}
	
	public AdministrationBean  selectByTableno(String tableno){
		return (AdministrationBean) ObjectUtil.transfer(administrationDao.selectByTableno(tableno), AdministrationBean.class);
	}
	
	public boolean updateAdministration(AdministrationBean administrationBean){
		Administration administration= (Administration) ObjectUtil.transfer(administrationBean, Administration.class);
		
		return administrationDao.updateAdministration(administration);
	}
	
	public boolean addFiled(String tablename,String filed, String type) {
		return administrationDao.addFile( tablename,filed, type);
	}
	
	public List<Administration> selectByTablename(String tablename){
		return administrationDao.selectByTablename(tablename);
	}
	
	public List<Administration> selectAll(){
		return administrationDao.selectAll();
	}

}
